<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>二维码-demo</title>
  <link rel="stylesheet" href="http://cdn.amazeui.org/amazeui/2.7.2/css/amazeui.css">
  <style>
    .btn-wrap {
      text-align: center;
    }
  </style>
</head>

<body>
  <div class="container">
    <div class="am-input-group">
      <input type="text" class="am-form-field" id="doc-qr-text">
      <span class="am-input-group-btn">
            <button class="am-btn am-btn-default" type="button" id="doc-gen-qr">生成</button>
          </span>
    </div>
    <div id="doc-qrcode" class="am-text-center"></div>
  </div>

  <div class="btn-wrap">
    <button type="button" class="am-btn am-btn-success am-radius" id="build_qrcode">点击生成二维码</button>
  </div>

  <div class="am-modal am-modal-prompt" tabindex="-1" id="qrcode_prompt">
    <div class="am-modal-dialog">
      <div class="am-modal-hd">我的二维码</div>
      <div class="am-modal-bd" id="show_qrcode"></div>
      <div class="am-modal-footer">
        推荐码：<mark></mark>
      </div>
    </div>
  </div>
</body>
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js"></script>
<script src="http://cdn.amazeui.org/amazeui/2.7.2/js/amazeui.js"></script>
<script src="../js/mui.js "></script>
<script src="../js/app.js"></script>

<script type="text/javascript">
  $(function() {
    // var $show

    $('#build_qrcode').on('click', function() {
      var tjCode = 'TJ' + app.createOrderNo().substr(-6),
        tempAddr = 'http://www.baidu.com?tj_code=' + tjCode;

      $('#show_qrcode').empty().qrcode(tempAddr);
      $('mark').text(tjCode);
      $('#qrcode_prompt').modal('open');

      // buildQrcode(tempAddr);
    });

    function buildQrcode(tempAddr) {
      $('#show_qrcode').empty().qrcode(tempAddr);

      $('#qrcode_prompt').modal('open');
    }

    var $input = $('#doc-qr-text'),
      $qr = $('#doc-qrcode');


    function makeCode(text) {
      $qr.empty().qrcode(text);
    }

    $input.val(location.href);
    makeCode(location.href);

    $('#doc-gen-qr').on('click', function() {
      makeCode($input.val());
    });

    $input.on('focusout', function() {
      makeCode($input.val());
    });
  });
</script>

</html>